import { PostAgreeLog } from "~/api";

export const useContent = () => {
    const dialogStore = useDialogStore();
    const orderStore = useOrderStore();
    const isChecked = ref(false);

    const onSubmitPay = async () => {
        if (isChecked.value) {
            dialogStore.isDetailDialogVisible = false;
            dialogStore.isPayDialogVisible = true;
        } else {
            Message().warning("请阅读购买协议并勾选！");
        }
    };

    const onClosed = () => {
        isChecked.value = false;
    };

    watch(isChecked, () => {
        if (isChecked.value) {
            const ua = navigator.userAgent;
            PostAgreeLog({
                user_agent: ua,
            });
        }
    });

    return {
        dialogStore,
        orderStore,
        isChecked,
        onSubmitPay,
        onClosed,
    };
};
